package school.course.coursetest;

import static org.junit.Assert.*;

import java.util.Date;

import javax.swing.text.DefaultEditorKit.PasteAction;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


import school.DateHelper;
import school.Instructor;
import school.Student;
import school.course.AbstractSimpleCourse;
import school.course.Course;
import school.course.Session;

public class testAbstractSimpleCourse {
	
	Date nearPast = DateHelper.getDateFromToday(-7);
	Date farPast= DateHelper.getDateFromToday(-2);
	Date now=DateHelper.getToday();
	Date nearFuture= DateHelper.getDateFromToday(2);
	Date farFuture= DateHelper.getDateFromToday(7);
	Course simpleCourse = new SimpleCourse();
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
			simpleCourse = new SimpleCourse(); //new course for each test
	}

	@Test
	public void testSetStartDate() {
		simpleCourse.setStartDate(nearPast);
		assertEquals(nearPast, simpleCourse.getStartDate());
		
		simpleCourse.setEndDate(farFuture);
		simpleCourse.setStartDate(null);
		assertEquals(null, simpleCourse.getStartDate());
		assertEquals(null, simpleCourse.getEndDate());
		
		simpleCourse.setStartDate(nearPast);
		simpleCourse.setEndDate(nearFuture);
		try {
			simpleCourse.setStartDate(farFuture);
		} catch (Exception e) {
			assertTrue(e.getClass()==RuntimeException.class);
			assertEquals(nearPast, simpleCourse.getStartDate());
			assertEquals(nearFuture, simpleCourse.getEndDate());
			return;
		}
		fail("Expect an exception");
	}

	@Test
	public void testSetEndDate() {
		simpleCourse.setStartDate(nearPast);
		simpleCourse.setEndDate(nearFuture);
		assertEquals(nearFuture, simpleCourse.getEndDate());
		
		simpleCourse.setStartDate(null);
		try {
			simpleCourse.setEndDate(nearFuture);
		} catch (Exception e) {
			assertEquals(e.getClass(),NullPointerException.class);
			assertEquals(null, simpleCourse.getStartDate());
			assertEquals(null, simpleCourse.getEndDate());
		}
		
		simpleCourse.setStartDate(now);
		simpleCourse.setEndDate(nearFuture);
		try {
			simpleCourse.setEndDate(nearPast);			
		} catch (Exception e) {
			assertEquals(e.getClass(),RuntimeException.class);
			assertEquals(now, simpleCourse.getStartDate());
			assertEquals(nearFuture, simpleCourse.getEndDate());
		}
	}

	@Test
	public void testIsEndsAfter() {
		simpleCourse.setStartDate(now);
		simpleCourse.setEndDate(now);
		assertTrue(simpleCourse.isEndsAfter(nearPast));
		assertTrue(simpleCourse.isEndsAfter(now));
		assertFalse(simpleCourse.isEndsAfter(nearFuture));
	}

	@Test
	public void testIsStartsBefore() {
		simpleCourse.setStartDate(now);
		simpleCourse.setEndDate(now);
		assertTrue(simpleCourse.isStartsBefore(nearFuture));
		assertTrue(simpleCourse.isStartsBefore(now));
		assertFalse(simpleCourse.isStartsBefore(nearPast));
	}

	public class SimpleCourse extends AbstractSimpleCourse {

		@Override
		public void removeStudent(Student student) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void addSession(Session session) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public boolean addStudent(Student student) {
			return true;
			
		}

		@Override
		public boolean setInstructor(Instructor instructor) {
			return true;
		}

		@Override
		public void setSessions(Session[] sessions) {
			// TODO Auto-generated method stub
			
		}
		
	}
}

